package com.zc.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zc.edu.entity.Course;
import com.zc.edu.entity.Teacher;
import com.zc.edu.service.CourseService;
import com.zc.edu.service.TeacherService;
import com.zc.utils.R;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduService/frontTeacher")
@CrossOrigin
public class TeacherFrontController {
	@Autowired
	private TeacherService teacherService;

	@Autowired
	private CourseService courseService;


	// 分页查询讲师
	@ApiOperation("前台分页查询讲师")
	@GetMapping("/pageTeacher/{currentPage}/{size}")
	public R pageListTeacher(@ApiParam(name = "currentPage", value = "当前页")@PathVariable("currentPage")long currentPage,
	                         @ApiParam(name = "size", value = "每页记录数")@PathVariable("size")long size) {
		Page<Teacher> pageTeacher = new Page<>(currentPage, size);
		Map<String, Object> pageInfo =  teacherService.getPageInfo(pageTeacher);

		return R.ok().data(pageInfo);
	}

	// 查询讲师信息
	@GetMapping("getTeacherInfo/{teacherId}")
	public R getTeacherInfo(@PathVariable String teacherId) {
		Teacher teacher = teacherService.getById(teacherId);

		QueryWrapper<Course> wrapper = new QueryWrapper<>();
		wrapper.eq("teacher_id", teacherId);
		List<Course> list = courseService.list(wrapper);
		return R.ok().data("teacher", teacher).data("courseList", list);
	}
}
